﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace Listas
{
    public class ComboBoxes
    {
        private ComboBox cbAt = new ComboBox();
        private ComboBox cbRemoveAt = new ComboBox();

        public int cbAtSelectedIndex
        {
            get { return cbAt.SelectedIndex; }
        }

        public int cbRemoveAtSelectedIndex
        {
            get { return cbRemoveAt.SelectedIndex; }
        }

        /// <summary>
        /// Creates the ComboBoxes that will contain the information about the k-positons where the node can be inserted or removed 
        /// </summary>
        /// <param name="gd">The grid to which the ComboBoxes will be added</param>
        public void createComboBoxes(Grid gd)
        {
            gd.Children.Add(cbAt);
            
            cbAt.Margin = new Thickness(0, 60, 25, gd.ActualHeight / 18);
            cbAt.VerticalAlignment = VerticalAlignment.Top;
            cbAt.HorizontalAlignment = HorizontalAlignment.Right;
            Grid.SetRow(cbAt, 5);
            Grid.SetColumn(cbAt, 1);

            gd.Children.Add(cbRemoveAt);
            
            cbRemoveAt.Margin = new Thickness(100, 60, 25, gd.ActualHeight / 18);
            cbRemoveAt.VerticalAlignment = VerticalAlignment.Top;
            cbRemoveAt.HorizontalAlignment = HorizontalAlignment.Left;
            Grid.SetRow(cbRemoveAt, 5);
            Grid.SetColumn(cbRemoveAt, 2);
            Grid.SetColumnSpan(cbRemoveAt, 2);

            initCbs();
        }

        /// <summary>
        /// Initializes the ComboBoxes.
        /// The ComboBox cbAt receives one element because it's possible to insert the first element at position one
        /// The ComboBox cbAt is only cleared because the list is empty and, therefore, there is no element to be removed
        /// </summary>
        public void initCbs()
        {
            cbAt.Items.Clear();
            cbAt.Items.Add((1).ToString() + "°");
            cbRemoveAt.Items.Clear();
        }

        /// <summary>
        /// Reset the ComboBoxes items
        /// </summary>
        internal void clearCbs()
        {
            cbAt.Items.Clear();
            cbRemoveAt.Items.Clear();
        }

        /// <summary>
        /// Updates the ComboBoxes' items adding the available positions to them
        /// </summary>
        /// <param name="contAdd"></param>
        /// <param name="numRetangulos"></param>
        internal void updateCbs(int contAdd, int numRetangulos)
        {
            for (int i = 1; i <= contAdd; i++)
            {
                cbAt.Items.Add(i.ToString() + "°");
                cbRemoveAt.Items.Add((i.ToString() + "°"));
            }
            if (contAdd != numRetangulos)
                cbAt.Items.Add((contAdd + 1).ToString() + "°");
        }
    }
}
